//==================================================================
/// particler.h
///
/// Created by Davide Pasca - 2009/10/5
/// See the file "license.txt" that comes with this project for
/// copyright info. 
//==================================================================

#ifndef PARTICLER_H
#define PARTICLER_H

#include "MathUtills.h"

class transformer;
class sprite;

//==================================================================
//==================================================================
class particler
{
	static const int    MAX_PARTS=256;

	//==================================================================
	struct Motion
	{
		int		life;
		int		flags;

		Vec3	pos;
		Vec3	vel;

		Motion()
		{
			life = 0;
			flags = 0;
			pos.SetZero();
			vel.SetZero();
		}
	};

	//==================================================================
	static const int    LIFE=0;
	static const int    FLAGS=1;
	static const int    DATA_SIZE=2;

	DVec<Motion>	mParts;
	int				mActiveN;

	float			_crea_speed, _crea_cnt;
	int				_lifespan;

	Vec3			mT0Speed;
	Vec3			mT0RandSize;
	Vec3			mRandSize1;
	Vec3			mRandSize2;
	Vec3			mAtten;

	transformer		*mpXFormer;
	sprite			*mpSptr;

	bool			mActive;

public:
	//==================================================================
	particler( transformer *pXFormer );

	//==================================================================
	void begin(
			float crea_speed,
			int lifespan,
			const Vec3 &t0Speed,
			const Vec3 &t0RandSize,
			const Vec3 &randSize1,
			const Vec3 &randSize2,
			const Vec3 &atten,
			sprite *pSptr );

	//==================================================================
	float rand_range( float x1, float x2 );

	//==================================================================
	void idle( float px, float py, float pz, float vx, float vy, float vz );

	//==================================================================
	void draw( graphics &g );

	//==================================================================
	bool is_active() const	{	return mActive;	}

	//==================================================================
	void end();

};

#endif
